package demo.api.trustsign;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import util.HttpClientUtil;

/**
 * 对消息（电子报文）进行验签
 *
 */
public class MessageVerify {
	private static String appKey = "cAwut4VATycNMq17NZeFUD63pe83l2OJ";
    private static String appSecrty = "3BAlrfr7lW8kwlCMfo1dXS8Syn5q5qjS";
    private static String baseUrl = "http://smp-test.szitrus.com.cn/smp-api/";
    private static String api = "/api/trustsign/message/verify";
    
	public static void main(String[] args) throws IOException {
		String url = baseUrl.concat(api);
		Map<String, String> params = new HashMap<>();
		
		params.put("data_type", "text");//base64, hex, text;
		params.put("plaintext", "我是签名原文");
		
		/*PKCS#7 Detached 签名值调用方式*/
//		params.put("signed_data", "MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCAMIIEkTCCA3mgAwIBAgIUFHEW0m3E/OUysu07cahlyaP7PFgwDQYJKoZIhvcNAQELBQAwgY0xRzBFBgNVBAMMPlNoZW4gWmhlbiBpVHJ1c0NoaW5hIENsYXNzIEVudGVycHJpc2UgU3Vic2NyaWJlciBDQSBSU0EgLSBUZXN0MRgwFgYDVQQLDA/mtYvor5Xpg6jor5XnlKgxGzAZBgNVBAoMEuWkqeivmuWuieS/oeivleeUqDELMAkGA1UEBhMCQ04wHhcNMjAwNTIwMTQzMTIxWhcNMjEwNTIwMTQzMTIxWjCBrDELMAkGA1UEBgwCQ04xODA2BgNVBAoML+a3seWcs+W4guWkqeWogeivmuS/oeenkeaKgOaciemZkOWFrOWPuCjmtYvor5UpMR0wGwYDVQQLDBRSU0Eg6K+B5Lmm77yI5rWL6K+VKTEwMC4GA1UECwwnVUlEOlvlsYXmsJHouqvku73or4FdMTEwMTAxMTk5MDAzMDc3NDMyMRIwEAYDVQQDDAnlvKDovr7lsbEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC1fl/6UT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Y3JpYmVyIENBIFJTQSAtIFRlc3QxGDAWBgNVBAsMD+a1i+ivlemDqOivleeUqDEbMBkGA1UECgwS5aSp6K+a5a6J5L+h6K+V55SoMQswCQYDVQQGEwJDTgIUFHEW0m3E/OUysu07cahlyaP7PFgwDQYJYIZIAWUDBAIBBQAwDQYJKoZIhvcNAQELBQAEggEAmWaJF2DsbDqCU+Ed3fUpU0F980rratuPErvzUGycttP607LXphfdmMmV2ABC2g/JKbqqTrvdzLPo0b0hMIVcMhwaIJv3pXO+KF5rqewKlz/Lx4MP2baXLk4B/ca0sUY8LphJDZXanp/7HyQgLyLncpPUGhRktElrMP1rDM3oCrK+gS5MFM8P6MeQgdSzyhUDbAgxdcUt9vU9uC3i0iaxf+EKVbcgKZH9Lb3XtZWE6qj+oy+tkGeLbKQHSErcA+tRqdZS5AzWFeAZExrqf2riZYdhHC4GVtdXT5gDAuom+LKYYMS71cjPD28lutMTQ6RlgcQ9TkrRj5mJF2kccPVX8AAAAAAAAA==");
//	    params.put("format", "detach");//raw=PKCS#1,attach=PKCS#7 attached, detach=PKCS#7 Detached
//	    params.put("algorithm", "SHA256withRSA");
	    
	    /*PKCS#7 Attached 签名值调用方式*/
		params.put("signed_data", "MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwGggCSABBLmiJHmmK/nrb7lkI3ljp/mlocAAAAAAACggDCCBJEwggN5oAMCAQICFBRxFtJtxPzlMrLtO3GoZcmj+zxYMA0GCSqGSIb3DQEBCwUAMIGNMUcwRQYDVQQDDD5TaGVuIFpoZW4gaVRydXNDaGluYSBDbGFzcyBFbnRlcnByaXNlIFN1YnNjcmliZXIgQ0EgUlNBIC0gVGVzdDEYMBYGA1UECwwP5rWL6K+V6YOo6K+V55SoMRswGQYDVQQKDBLlpKnor5rlronkv6Hor5XnlKgxCzAJBgNVBAYTAkNOMB4XDTIwMDUyMDE0MzEyMVoXDTIxMDUyMDE0MzEyMVowgawxCzAJBgN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a12a7WJsZhLBpN0QHlsRTRr7RBuqwvukej3UKgK8EQ/oF3L5wMESfcA9AWcD0WHd/qQy+7NNbE7yWKeKA4Vm7BPkRKdh7fYOad0QkMX+7wsVz6ThK4j65lfiuruLhlmgSPNz0MLIL5S4FDSvANV3W+U1fFlH+osiVuAJMoODu3s5iBX+fDqwTTNVfgAAMYIB0jCCAc4CAQEwgaYwgY0xRzBFBgNVBAMMPlNoZW4gWmhlbiBpVHJ1c0NoaW5hIENsYXNzIEVudGVycHJpc2UgU3Vic2NyaWJlciBDQSBSU0EgLSBUZXN0MRgwFgYDVQQLDA/mtYvor5Xpg6jor5XnlKgxGzAZBgNVBAoMEuWkqeivmuWuieS/oeivleeUqDELMAkGA1UEBhMCQ04CFBRxFtJtxPzlMrLtO3GoZcmj+zxYMA0GCWCGSAFlAwQCAQUAMA0GCSqGSIb3DQEBCwUABIIBAJlmiRdg7Gw6glPhHd31KVNBffNK62rbjxK781BsnLbT+tOy16YX3ZjJldgAQtoPySm6qk673cyz6NG9ITCFXDIcGiCb96Vzvihea6nsCpc/y8eDD9m2ly5OAf3GtLFGPC6YSQ2V2p6f+x8kIC8i53KT1BoUZLRJazD9awzN6AqyvoEuTBTPD+jHkIHUs8oVA2wIMXXFLfb1Pbgt4tImsX/hClW3ICmR/S2917WVhOqo/qMvrZBni2ykB0hK3APrUanWUuQM1hXgGRMa6n9q4mWHYRwuBlbXV0+YAwLqJviymGDEu9XIzw9vJbrTE0OkZYHEPU5K0Y+ZiRdpHHD1V/AAAAAAAAA=");
	    params.put("format", "attach");//raw=PKCS#1,attach=PKCS#7 Attached, detach=PKCS#7 Detached
	    params.put("algorithm", "SHA256withRSA");
	    
		/*PKCS#1签名值调用方式*/
//	    params.put("signed_data", "mWaJF2DsbDqCU+Ed3fUpU0F980rratuPErvzUGycttP607LXphfdmMmV2ABC2g/JKbqqTrvdzLPo0b0hMIVcMhwaIJv3pXO+KF5rqewKlz/Lx4MP2baXLk4B/ca0sUY8LphJDZXanp/7HyQgLyLncpPUGhRktElrMP1rDM3oCrK+gS5MFM8P6MeQgdSzyhUDbAgxdcUt9vU9uC3i0iaxf+EKVbcgKZH9Lb3XtZWE6qj+oy+tkGeLbKQHSErcA+tRqdZS5AzWFeAZExrqf2riZYdhHC4GVtdXT5gDAuom+LKYYMS71cjPD28lutMTQ6RlgcQ9TkrRj5mJF2kccPVX8A==");
//	    params.put("format", "raw");
//	    params.put("algorithm", "SHA256withRSA");
//	    params.put("cert_encoded", "MIIEkTCCA3mgAwIBAgIUFHEW0m3E/OUysu07cahlyaP7PFgwDQYJKoZIhvcNAQELBQAwgY0xRzBFBgNVBAMMPlNoZW4gWmhlbiBpVHJ1c0NoaW5hIENsYXNzIEVudGVycHJpc2UgU3Vic2NyaWJlciBDQSBSU0EgLSBUZXN0MRgwFgYDVQQLDA/mtYvor5Xpg6jor5XnlKgxGzAZBgNVBAoMEuWkqeivmuWuieS/oeivleeUqDELMAkGA1UEBhMCQ04wHhcNMjAwNTIwMTQzMTIxWhcNMjEwNTIwMTQzMTIxWjCBrDELMAkGA1UEBgwCQ04xODA2BgNVBAoML+a3seWcs+W4guWkqeWogeivmuS/oeenkeaKgOaciemZkOWFrOWPuCjmtYvor5UpMR0wGwYDVQQLDBRSU0Eg6K+B5Lmm77yI5rWL6K+VKTEwMC4GA1UECwwnVUlEOlvlsYXmsJHouqvku73or4FdMTEwMTAxMTk5MDAzMDc3NDMyMRIwEAYDVQQDDAnlvKDovr7lsbEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC1fl/6UTMYXq/owAzuDGqKXQmGAeF/39V5km0QfhQSx2M8r1mV4Is//v807kf6DzZuIP/joPE4k26GdCuabyf24l1uE5um0s2JL5/lDnnA71bcElmyJ1dagRMumCTzHZueze/jkeTrvM4RxBW8J4f8IhPpW2mhUPiOc13nl8wTrtknGM/m6YhSzWdF5nwe7iVtH9DnUe0B5x6LDTNGpO3mI7UoznsdkxHgYrV3r3tTTOR9IFcLp+1WHEv8S9gvGLZLI35EEZLoQQSCDN1bTWFbdOybwcrGhbbQEweqBlQWMsr5JKcV3vsaCIrQuwmyt0th6qZfKPuXikWRidEYgxarAgMBAAGjgccwgcQwCQYDVR0TBAIwADALBgNVHQ8EBAMCBsAwagYDVR0fBGMwYTBfoF2gW4ZZaHR0cDovL3N6dG9wY2Euc3ppdHJ1cy5jb20uY24vcHVibGljL2l0cnVzY3JsP0NBPTY5Qzk0N0M3RUY2MDlFNkFDN0ZGNjIxMzRFNjhGRjZBMDg5NTcyMDIwHwYDVR0jBBgwFoAUEKRPH67l+ANlIkYfK+IZGiyAvY4wHQYDVR0OBBYEFKmxxFc5l7oDiSo+xU5A7b57bJTIMA0GCSqGSIb3DQEBCwUAA4IBAQAlYQ+w1zacs4w9WhNrsC2gfwGuzrbtTuykKs+bE1EVIEbfp9q1/ffcUylbDl74mlwj8HX1dt3RubWgKT37n8detIzol1yABQE11DoYOQVl2SUEygLEnrCdNYP1bZl4T4I/VuyA79KnPwelIioLB4cgat+Z+fZrXZrtYmxmEsGk3RAeWxFNGvtEG6rC+6R6PdQqArwRD+gXcvnAwRJ9wD0BZwPRYd3+pDL7s01sTvJYp4oDhWbsE+REp2Ht9g5p3RCQxf7vCxXPpOEriPrmV+K6u4uGWaBI83PQwsgvlLgUNK8A1Xdb5TV8WUf6iyJW4Akyg4O7ezmIFf58OrBNM1V+");//format =raw时，该值必须有
	    
	    String resStr =  HttpClientUtil.getResponse(url, params, appKey, appSecrty);
	    JSONObject resJson = JSON.parseObject(resStr);	
	    System.out.println(resJson);
	}
}
